let form1=document.querySelector('.fo')
// let errBox=document.querySelector('.error');
let nameInp1=document.querySelector('.name');
let pwdInp1=document.querySelector('.pwd1');
let supwdInp=document.querySelector('.pwd2');
let nickInp=document.querySelector('.nick');

form1.addEventListener('submit',async e=>{
    // localStorage.removeItem('token');
    e.preventDefault();
    // console.log('111')
    let username=nameInp1.value;
    // let username=name;
    let password=pwdInp1.value;
    let rpassword=supwdInp.value;
    let nickname=nickInp.value;

    if(!username||!password||!nickname||!rpassword) return alert('请完整填写表单');
    if(password!=rpassword) return alert('两次密码不一致');
    let {data} = await http.post('/users/register',{username,password,rpassword,nickname});
    console.log(data)
    if(data.code !=1) alert('请重试');
    if(data.code==1){
        alert('恭喜注册成功，点击确定跳转登录页面！')
    location.href='./login.html'
    }
})